package com.ruicar.afs.cloud.apply.admin.manage.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.apply.admin.manage.entity.SysPermission;
import com.ruicar.afs.cloud.apply.admin.manage.mapper.ApplyPermissionMapper;
import com.ruicar.afs.cloud.apply.admin.manage.service.ApplyPermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author: Lee
 * @date: 2020/06/05
 * @description:
 */
@Slf4j
@Service
public class ApplyPermissionServiceImpl extends ServiceImpl<ApplyPermissionMapper, SysPermission> implements ApplyPermissionService {
    /**
     * Find by level order by sort order list.
     *
     * @param level the level
     * @return the list
     */
    @Override
    public List<SysPermission> findByLevelOrderBySortOrder(Integer level) {

        return this.list(Wrappers
                .<SysPermission>query().lambda()
                .eq(SysPermission::getLevel, level)
        );
    }

    /**
     * Find by parent id order by sort order list.
     *
     * @param parentId the parent id
     * @return the list
     */
    @Override
    public List<SysPermission> findByParentIdOrderBySortOrder(String parentId) {
        return this.list(Wrappers
                .<SysPermission>query().lambda()
                .eq(SysPermission::getParentId, parentId).orderByAsc(SysPermission::getSortOrder)
        );
    }

    /**
     * Find by type and status order by sort order list.
     *
     * @param type   the type
     * @param status the status
     * @return the list
     */
    @Override
    public List<SysPermission> findByTypeAndStatusOrderBySortOrder(Integer type, String status) {
        return this.list(Wrappers
                .<SysPermission>query().lambda()
                .eq(SysPermission::getType, type).eq(SysPermission::getStatus, status).orderByAsc(SysPermission::getSortOrder));
    }

    /**
     * Find by title list.
     *
     * @param title the title
     * @return the list
     */
    @Override
    public List<SysPermission> findByTitle(String title) {
        return this.list(Wrappers
                .<SysPermission>query().lambda()
                .eq(SysPermission::getTitle, title).orderByAsc(SysPermission::getSortOrder));
    }

    /**
     * Find by title like order by sort order list.
     *
     * @param title the title
     * @return the list
     */
    @Override
    public List<SysPermission> findByTitleLikeOrderBySortOrder(String title) {
        return this.list(Wrappers
                .<SysPermission>query().lambda()
                .like(SysPermission::getTitle, title).orderByAsc(SysPermission::getSortOrder));
    }

    @Override
    public List<SysPermission> findByUserId(Long userId) {
        return baseMapper.findByUserId(userId);
    }
}
